package com.spi.config;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import com.xxl.job.core.handler.IJobHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;

import javax.annotation.PostConstruct;
import java.util.Map;

@Configuration
@ComponentScan(basePackages = {"com.spi.xxjob.executer2"},
        excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = "com\\.spi\\.xxjob\\.executor1\\..*"))
public class XxlJobConfig2 {

    @Value("${xxl.job.admin.addresses}")
    private String adminAddresses;

    @Value("${xxl.job.executor2.appname}")
    private String appname2;

    @Value("${xxl.job.executor2.ip}")
    private String ip2;

    @Value("${xxl.job.executor2.port}")
    private int port2;

    @Value("${xxl.job.executor2.logpath}")
    private String logPath2;

    @Value("${xxl.job.executor2.logretentiondays}")
    private int logRetentionDays2;

    @Value("${xxl.job.executor2.accessToken}")
    private String accessToken2;

    @Autowired
    private ApplicationContext applicationContext;

    @Bean
    public XxlJobSpringExecutor xxlJobExecutor2() {
        //logger.info(">>>>>>>>>>> xxl-job config init for executor2.");
        System.out.println("执行器2初始化完毕");
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
        xxlJobSpringExecutor.setAppname(appname2);
        xxlJobSpringExecutor.setIp(ip2);
        xxlJobSpringExecutor.setPort(port2);
        xxlJobSpringExecutor.setLogPath(logPath2);
        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays2);
        xxlJobSpringExecutor.setAccessToken(accessToken2);
        return xxlJobSpringExecutor;
    }
}
